//ACCEPTED
#include <cstdio>
int t[300][300], n, i, j, k, a, b, c, sum=0;
void read(){
	scanf("%d", &n);
	for(i=0;i<n;i++)
		for(j=0;j<n;j++){
			scanf("%d", &t[i][j]);
			if(j>i)sum+=t[i][j];
		}
}
void process(){
	scanf("%d", &k);
	for(i=0;i<k;i++){
		scanf("%d %d %d", &a, &b, &c);
		sum+=c-t[a-1][b-1];
		printf("%d ", sum);
	}
	
}
int main(){
	freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
	read();
	process();
	return 0;
}
